﻿<%@ Page Title="QC RM" Language="C#" MasterPageFile="~/TableMaster.master" AutoEventWireup="true" CodeFile="qc_RM.aspx.cs" Inherits="Pages_qc_RM" EnableEventValidation="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">

    <style>
        @media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) {

            .resTbl tr:nth-of-type(odd) {
                background-color: #CDE2FF;
            }

            .resTbl tr:nth-of-type(1) {
                display: none;
            }

            .resTbl td:nth-of-type(1):before {
                content: "RM Order #";
            }

            .resTbl td:nth-of-type(2):before {
                content: "Bag #";
            }

            .resTbl td:nth-of-type(3):before {
                content: "Drum #";
            }

            .resTbl td:nth-of-type(4):before {
                content: "Date";
            }

            .resTbl td:nth-of-type(5):before {
                content: "Al";
            }

            
            .resTbl td:nth-of-type(5):before {
                content: "C";
            }

            
            .resTbl td:nth-of-type(5):before {
                content: "Ca";
            }

            
            .resTbl td:nth-of-type(5):before {
                content: "Fe";
            }

            .resTbl td:nth-of-type(6):before {
                content: "Grade";
            }

            .resTbl td:nth-of-type(7):before {
                content: "Is Active";
            }

            .resTbl td:nth-of-type(8):before {
                content: "Created By";
            }

            .resTbl td:nth-of-type(9):before {
                content: "Created Date";
            }
        }
    </style>
    <script type="text/javascript">

        var ddlRM_Order_Number, ddlBag_Number, ddlDrum_Number;

        $(document).ready(function () {
            ddlRM_Order_Number = $("#<%=ddlRM_Order_Number.ClientID%>");
             ddlBag_Number = $("#<%=ddlBag_Number.ClientID%>");
             ddlDrum_Number = $("#<%=ddlDrum_Number.ClientID%>");

             ddlRM_Order_Number.change(function () {
                 getDrums();
                 getBags();
             });
         });

        function save() {
            var BagValue = $('#MainContent_Add_ddlBag_Number').val();
            var DrumValue = $('#MainContent_Add_ddlDrum_Number').val();
            if ((BagValue == "0") && (DrumValue == null) || (BagValue == null) && (DrumValue == "0")) {

                alert('Please Select Bag or Drum Number');
                return;
            }
            var RM_Order_Number = $('#MainContent_Add_ddlRM_Order_Number').val();
            var Date = $('#MainContent_Add_txtDate').val();
            var Al = $('#MainContent_Add_txtAl').val();
            var C = $('#MainContent_Add_txtC').val();
            var Ca = $('#MainContent_Add_txtCa').val();
            var Fe = $('#MainContent_Add_txtFe').val();
            var Grade = $('#MainContent_Add_ddlGrade').val();

            if (RM_Order_Number == "0") {
                alert('Please Select RM Order Number');
                return;
            }
            if (Date == "") {
                alert('Please enter Date');
                return;
            }         
           
            if (Al == "") {
                alert('Please enter Al');
                return;
            }
            if (C == "") {
                alert('Please enter C');
                return;
            }
            if (Ca == "") {
                alert('Please enter Ca');
                return;
            }
            if (Fe == "") {
                alert('Please enter Fe');
                return;
            }
            if (Grade == "0") {
                alert('Please Select Grade');
                return;
            }
             var inputs = ["MainContent_Add_ddlRM_Order_Number", "MainContent_Add_ddlBag_Number", "MainContent_Add_ddlDrum_Number", "MainContent_Add_txtDate", "MainContent_Add_txtAl", "MainContent_Add_txtC", "MainContent_Add_txtCa", "MainContent_Add_txtFe", "MainContent_Add_ddlGrade"];
             var fields = ["RM_Order_Number", "Bag_Number", "Drum_Number", "Date", "Al", "C", "Ca", "Fe", "Grade"];
             var editurl = (window.location.search).split('=');
             var Id = editurl[editurl.length - 1];
             if (Id == "") {
                 saveData('mytable', fields, inputs, 'Services.aspx/save_qc_RM');
             }
             else {
                 
                 updateData('mytable', fields, inputs, 'Services.aspx/update_qc_RM', Id, "ID");
             }
         }


         function getDrums() {
             if (window.location.search != "") {
                 ddlRM_Order_Number = $("#<%=ddlRM_Order_Number.ClientID%>");
                 ddlBag_Number = $("#<%=ddlBag_Number.ClientID%>");
                 ddlDrum_Number = $("#<%=ddlDrum_Number.ClientID%>");
             }            
             
                 ddlDrum_Number.empty();
                 ddlDrum_Number.append("<option>Loading...</option>");             

             $.ajax({
                 type: "POST",
                 url: "http://" + window.location.host + "/Inventory/Services/Services.aspx/getDrumNumber",
                 data: "{'RMOrder': '" + ddlRM_Order_Number.val() + "'}",
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",
                 success: function (data) {

                     ddlDrum_Number.empty();

                     if (data.d.length == 0)
                         return;

                     ddlDrum_Number.append("<option value='0'>--Select DRUM--</option>");
                     $.each(data, function (i, item) {
                         $.each(item, function (j, ddlItem) {
                             ddlDrum_Number.append('<option  value="' + ddlItem.Drum_Number + '"> ' + ddlItem.Drum_Number + '</option>');
                         });
                         $('#MainContent_Add_ddlDrum_Number').val($('#MainContent_Add_ddlDrum_Number').attr('selectedval'));
                     });
                 }
             });
         }

         function updateDropDownValue() {

         }

         function getBags() {

             if (window.location.search != "") {
                 ddlRM_Order_Number = $("#<%=ddlRM_Order_Number.ClientID%>");
                  ddlBag_Number = $("#<%=ddlBag_Number.ClientID%>");
                  ddlDrum_Number = $("#<%=ddlDrum_Number.ClientID%>");
              }
             ddlBag_Number.empty();
             ddlBag_Number.append("<option>Loading...</option>");

             $.ajax({
                 type: "POST",
                 url: "http://" + window.location.host + "/Inventory/Services/Services.aspx/getBagNumber",
                 data: "{'RMOrder': '" + ddlRM_Order_Number.val() + "'}",
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",
                 success: function (data) {
                     ddlBag_Number.empty();

                     if (data.d.length == 0)
                         return;

                     ddlBag_Number.append("<option value='0'>--Select BAG--</option>");
                     $.each(data, function (i, item) {
                         $.each(item, function (j, ddlItem) {
                             ddlBag_Number.append('<option  value="' + ddlItem.Bag_Number + '"> ' + ddlItem.Bag_Number + '</option>');
                         });
                         $('#MainContent_Add_ddlBag_Number').val($('#MainContent_Add_ddlBag_Number').attr('selectedval'));
                     });
                 }
             });
         }


    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Add" runat="Server">

    <asp:Panel ID="pnlAdd" runat="server" CssClass="qcbg">


        <table id="mytable" cellpadding="0" cellspacing="0" width="80%">

            <tr>
                <td style="width: 170px">
                    <asp:Label ID="lblRM_Order_Number" runat="server" AssociatedControlID="ddlRM_Order_Number" Text="RM Order #:"></asp:Label>
                </td>
                <td style="width: 112px">
                    <asp:Label ID="lblBag_Number" runat="server" AssociatedControlID="ddlBag_Number" Text="Bag #:"></asp:Label>
                </td>
                <td style="width: 170px">
                    <asp:Label ID="lblDrum_Number" runat="server" AssociatedControlID="ddlDrum_Number" Text="Drum #:"></asp:Label>
                </td>
                <td style="width: 170px">
                    <asp:Label ID="lblDate" runat="server" AssociatedControlID="txtDate" Text="Date:"></asp:Label>
                </td>
                <td style="width: 170px">
                    <asp:Label ID="lblFe" runat="server" AssociatedControlID="txtFe" Text="Fe:"></asp:Label>
                </td>
                <td style="width: 170px">
                    <asp:Label ID="lblCa" runat="server" AssociatedControlID="txtCa" Text="Ca:"></asp:Label>
                </td>
                <td style="width: 70px">
                    <asp:Label ID="lblAl" runat="server" AssociatedControlID="txtAl" Text="Al:"></asp:Label>
                </td>
                <td style="width: 170px">
                    <asp:Label ID="lblC" runat="server" AssociatedControlID="txtC" Text="C:"></asp:Label>
                </td>
                <td style="width: 170px">
                    <asp:Label ID="lblGrade" runat="server" AssociatedControlID="ddlGrade" Text="Grade:"></asp:Label>
                </td>
                <td></td>
            </tr>

            <tr>
                <td style="width: 170px">
                    <asp:DropDownList ID="ddlRM_Order_Number" runat="server" AppendDataBoundItems="True" DataSourceID="DS_RMOrderID" DataTextField="RM_Order_Number" DataValueField="RM_Order_Number" EnableViewState="False" Width="108px">
                        <asp:ListItem Value="0">--Select--</asp:ListItem>
                    </asp:DropDownList>
                    <asp:ObjectDataSource ID="DS_RMOrderID" runat="server" SelectMethod="getRM_Order_Number" TypeName="DAL_tbl_rm_receipt"></asp:ObjectDataSource>
                </td>
                <td style="width: 112px">
                    <asp:DropDownList ID="ddlBag_Number" runat="server" Width="103px"></asp:DropDownList>
                </td>
                <td style="width: 170px">
                    <asp:DropDownList ID="ddlDrum_Number" runat="server" Width="103px"></asp:DropDownList>
                </td>
                <td style="width: 170px">
                    <asp:TextBox ID="txtDate" type="date" runat="server" Width="150px"></asp:TextBox>
                </td>
                <td style="width: 170px">
                    <asp:TextBox ID="txtFe" runat="server" EnableViewState="False" Width="75px" validate="Number"></asp:TextBox>
                </td>
                <td style="width: 170px">
                    <asp:TextBox ID="txtCa" runat="server" EnableViewState="False" Width="75px" validate="Number"></asp:TextBox>
                </td>
                <td style="width: 70px">
                    <asp:TextBox ID="txtAl" runat="server" Width="75px" validate="Number"></asp:TextBox>
                </td>
                <td style="width: 170px">
                    <asp:TextBox ID="txtC" runat="server" EnableViewState="False" Width="75px" validate="Decimal"></asp:TextBox>
                </td>
                <td style="width: 170px">
                    <asp:DropDownList ID="ddlGrade" runat="server" Width="103px">
                        <asp:ListItem Value="0">--Select--</asp:ListItem>
                        <asp:ListItem>2</asp:ListItem>
                        <asp:ListItem>4</asp:ListItem>
                        <asp:ListItem>4N</asp:ListItem>
                        <asp:ListItem>HP</asp:ListItem>
                        <asp:ListItem>SiB</asp:ListItem>
                        <asp:ListItem>Si-Al</asp:ListItem>
                        <asp:ListItem>R</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    <button type="button" class="btn btn-default btn-xs" onclick="removeRow(this);"><span class="glyphicon glyphicon-remove"></span></button>
                </td>
            </tr>

        </table>
        <button type="button" class="btn btn-default btn-xs" onclick="addRow('mytable');"><span class="glyphicon glyphicon-plus"></span>Add Row</button>

        <br />

        <br />
        
        <input type="button" id="btnsave" value="Save" style="width: 90px" class="btn btn-success" onclick="save();" />
            

        
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="btnCancel" runat="server" CssClass="btn btn-danger" OnClick="btnCancel_Click" Text="Cancel" Width="90px" />

            </asp:Panel>
       
        
        

            
    </asp:Panel>


</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Grid" runat="Server">

    <asp:Panel ID="pnlList" runat="server">
        <asp:GridView ID="gridClients" runat="server" AutoGenerateColumns="False" CssClass="resTbl" DataSourceID="DS_tbl_qc_rm">
            <Columns>
                <asp:BoundField DataField="RM_Order_Number" HeaderText="RM Order #" SortExpression="RM_Order_Number" />
                <asp:BoundField DataField="Bag_Number" HeaderText="Bag #" SortExpression="Bag_Number" />
                <asp:BoundField DataField="Drum_Number" HeaderText="Drum #" SortExpression="Drum_Number" />
                <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" DataFormatString="{0:yyMMdd}" />
                <asp:BoundField DataField="Al" HeaderText="Al" SortExpression="Al" />
                <asp:BoundField DataField="C" HeaderText="C" SortExpression="C" />
                <asp:BoundField DataField="Ca" HeaderText="Ca" SortExpression="Ca" />
                <asp:BoundField DataField="Fe" HeaderText="Fe" SortExpression="Fe" />
                <asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" />
                <asp:BoundField DataField="IS_ACTIVE" HeaderText="Is Active" SortExpression="IS_ACTIVE" />
                <asp:BoundField DataField="CREATED_BY" HeaderText="Created By" SortExpression="CREATED_BY" />
                <asp:BoundField DataField="CREATED_DATE" HeaderText="Created Date" SortExpression="CREATED_DATE" DataFormatString="{0:yyMMdd}" />

                <asp:TemplateField HeaderText="Edit">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkEdit" runat="server" Text="Edit" CommandArgument='<%# Eval("ID") %>' OnClick="linkEdit_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkDelete" CommandName="delete" runat="server" Text="Delete" OnClientClick="javascript:return confirm('Are you sure you want to delete this record?');" CommandArgument='<%# Eval("ID") %>' OnClick="linkDelete_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="DS_tbl_qc_rm" runat="server" SelectMethod="selectAllForGrid" DeleteMethod="delete" InsertMethod="insert" UpdateMethod="update" TypeName="DAL_tbl_qc_rm">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="String" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="RM_Order_Number" Type="String" />
                <asp:Parameter Name="Bag_Number" Type="String" />
                <asp:Parameter Name="Drum_Number" Type="String" />
                <asp:Parameter Name="Date" Type="DateTime" />
                <asp:Parameter Name="Al" Type="Int32" />
                <asp:Parameter Name="C" Type="String" />
                <asp:Parameter Name="Ca" Type="Int32" />
                <asp:Parameter Name="Fe" Type="Int32" />
                <asp:Parameter Name="Grade" Type="String" />
                <asp:Parameter Name="IS_ACTIVE" Type="Boolean" />
                <asp:Parameter Name="CREATED_BY" Type="String" />
                <asp:Parameter Name="CREATED_DATE" Type="DateTime" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="RM_Order_Number" Type="String" />
                <asp:Parameter Name="Bag_Number" Type="String" />
                <asp:Parameter Name="Drum_Number" Type="String" />
                <asp:Parameter Name="Date" Type="DateTime" />
                <asp:Parameter Name="Al" Type="Int32" />
                <asp:Parameter Name="C" Type="String" />
                <asp:Parameter Name="Ca" Type="Int32" />
                <asp:Parameter Name="Fe" Type="Int32" />
                <asp:Parameter Name="Grade" Type="String" />
                <asp:Parameter Name="IS_ACTIVE" Type="Boolean" />
                <asp:Parameter Name="CREATED_BY" Type="String" />
                <asp:Parameter Name="CREATED_DATE" Type="DateTime" />
            </UpdateParameters>
        </asp:ObjectDataSource>
    </asp:Panel>

</asp:Content>

